/* autor Konjkov.VV@gmail.com */

#include <stdio.h>
#include <string.h>

#include "node.h"
#include "common.h"

int node_add(char *node)
{
SQLHSTMT  stmt;
SQLRETURN retcode;
// todo check in node is not alredy exist
// todo create subdirs

    SQLAllocStmt( dbc, &stmt );
    EXEC_SQL( SQLPrepare( stmt, "INSERT INTO mcc.syncNODES(name) VALUES(?);", SQL_NTS ) );
    EXEC_SQL( SQLBindParameter( stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 30, 0, node, 0, SQL_TYPE_NULL) );
//    EXEC_SQL( SQLExecDirect( stmt, "INSERT INTO mcc.syncNODES(name) VALUES(?);", SQL_NTS ) );
    EXEC_SQL( SQLExecute( stmt ) );
    SQLFreeStmt( stmt, SQL_CLOSE );

    return 0;
}

int node_remove(char *node)
{
SQLHSTMT  stmt;
SQLRETURN retcode;
// todo check in node is alredy exist

    SQLAllocStmt( dbc, &stmt );
    EXEC_SQL( SQLBindParameter( stmt, 1, SQL_PARAM_INPUT, SQL_C_CHAR, SQL_CHAR, 30, 0, node, 0, SQL_TYPE_NULL) );
    EXEC_SQL( SQLExecDirect( stmt, "DELETE FROM mcc.syncnodes WHERE name = ?;", SQL_NTS ) );
    SQLFreeStmt( stmt, SQL_CLOSE );

    return 0;
}

int node_reset(char *node) {
// todo check in node is alredy exist
    prepared_set(node, 0);
// todo remove outgoing packets
    return 0;
}

int node_list(char *node) {
SQLHSTMT stmt;
// todo
    return 0;
}
